package tech.aistar.mapper;

import org.apache.ibatis.annotations.*;
import tech.aistar.model.pojo.Cart;

import java.util.List;

public interface CartMapper {
    void save(Cart cart);

    @Update("update cart set counts = counts+1,price=product_price*counts where product_id=#{productId} and user_id=#{userId}")
    void update(@Param("productId") Integer productId,@Param("userId") Integer userId);

    @Select("select * from cart where product_id=#{productId} and user_id=#{userId}")
    Cart find(@Param("productId") Integer productId,@Param("userId") Integer userId);

    @Select("select * from cart where user_id=#{value}")
    List<Cart> findAll(Integer userId);

    @Delete("delete from cart where id=#{value}")
    int delById(Integer id);

    @Update("update cart set counts=#{num},price=product_price*counts where id=#{id}")
    int updates(@Param("id")Integer cid,@Param("num") Integer num);

    @Select("select * from cart where id=#{value}")
    Cart getById(Integer id);
}